package com.wuliupai.delivery.wuliupaidelivery.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wuliupai.delivery.wuliupaidelivery.R;

import java.util.List;


/**
 * Descriptions：订单中价格相关的Adapter
 * <p>
 * Author：ChenME
 * Date：11/26/2016
 * Email：ibelieve1210@163.com
 */
public class OrderPriceListAdapter extends BaseAdapter {

    private List<String[]> dataList;
    private Context context;

    public OrderPriceListAdapter(Context context, List<String[]> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return null != dataList ? dataList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_order_detail_price_list, null);
            holder.tv_priceName = (TextView) convertView.findViewById(R.id.tv_priceName);
            holder.tv_price = (TextView) convertView.findViewById(R.id.tv_price);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String[] result = dataList.get(position);
        try {
            holder.tv_priceName.setText(result[0]+"：");

            String price = result[1];
            if (price.contains("-")) {
                holder.tv_price.setTextColor(context.getResources().getColor(R.color.color_textOrange));
            } else {
                holder.tv_price.setTextColor(context.getResources().getColor(R.color.color_defaultTextDark));
            }
            holder.tv_price.setText(price);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }

    class ViewHolder {
        TextView tv_priceName;
        TextView tv_price;
    }
}